

    import Hello from '../Hello.vue?t=23223'



    function selectPaper3(index){
        app.$data.currentPaper = app.$data.list[index];
    }

    function selectTexture(textureId){
        for(var i=0;i<app.$data.textureList.length;i++){
            var se = app.$data.textureList[i];
            if(se.id == textureId){
                return se;
                break;
            }
        }
        return null;
    }
    function submitAllPaper(){
        for(var i=0;i<app.$data.list.length;i++){
            var se = app.$data.list[i];
            if(se.changed){
                submit(se);
            }
        }
    }
function submit(se){
    if(!se || !se.changed) return;
    console.log(se);
    axios.post(`/zb/${se.sellerId}/paper/update`, se).then(function (response) {
        console.log("response",response)
    }).catch(function (error) {
        console.log("error",error);
    });
}
function newPaper(sellerId){
    if(!sellerId) return;
    var paper = {
        sellerId: sellerId,
        name:''
    };
    app.$data.currentPaper = paper;
    app.$data.list.push(paper);

}
const { createApp } = Vue;
    var app = createApp({
    data() {
      return {
        message: 'Hello Vue!',
        list:[],
        textureList:[],
        paperIndex:-1,
        currentPaper: null,
        selector:{target:{}}
      }
    },methods:{
        selectPaper:function(i){
            app.$data.paperIndex=i;
            app.$data.currentPaper = app.$data.list[i];
        },submitPaper:function(index){
            var paper = app.$data.list[index];
            submit(paper);
        }, search:function (){
            console.log('aaaaaaaaaaaaaa')
              loadData(sellerId)
        }
    },
    watch:{
        currentPaper:{
            handler:function(nv,ov){
                nv.changed=true;
            },deep:true
        },"currentPaper.textureId":{
            handler:function(nv,ov){
                console.log("currentPaper.textureId",nv)
                if(nv){
                    var texture = selectTexture(nv);
                    if(texture) app.$data.currentPaper.textureName = texture.name
                }
            },deep:true
        }
    }
  }).mount('#app');


function loadData(sellerId){
    var selector  = app.$data.selector || { target:{} };
    selector.target = selector.target || {};
    selector.target.sellerId =  selector.target.sellerId  || sellerId;
    axios.post(`/zb/${sellerId}/paper/list`, selector).then(function (response) {
        console.log("response",response)
        app.$data.list = response.data.data;
    }).catch(function (error) {
        console.log("error",error);
    });
}

function loadTextureData(app){
    console.log("load")
    axios.post(`/common/texture/list`, {}).then(function (response) {
        app.$data.textureList = response.data.data || [];
    }).catch(function (error) {
        console.log("error",error);
    });
}
window.onload=function(){
   loadData(sellerId);
   loadTextureData(app);
}
export { newPaper,submitAllPaper,app}

